package com.miracle9.game.util.encryptionalgorithm;

import java.io.PrintStream;
import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import javax.crypto.Cipher;

public class EncryptionOperating
{
  private static String cv = "mSs9e2zYPFDs8nuNl8safQ1pNvhskGg2opu7AHmPoGODnp6jFoI4C0tXa4KQMUg1SjOPVipP4grEl6q8G+QwQIrLpVo1n6tnK09GCWsUyTjG/Y75totuRxx+fWpVH0eWNdgO7ZGAk0H1b0kCH4ENUUW51z+d+Xt5A53xkRzyCSU=";
  private static String cw = "AQAB";
  private static String cx = "SbownAqmg1II3Cdw3pIbK/qanKUzzMb9FYSUnQPmiLOeFWoS4rDHvVgEunFcavxw+kibRESVsx6vxrmeVmaeepQeJ7lqj1GJSbRAOoOLaI1KEY0QzsjNTlY1peKa/ZQ8+dNs1D+fD4O7uWmJxzEZetWYrzEo36EEDX8x3a9uZAE=";
  public PublicKey cy;
  public PrivateKey cz;
  private static EncryptionOperating cA;
  
  public static EncryptionOperating r()
  {
    if (cA == null)
    {
      cA = new EncryptionOperating();
      cA.init();
    }
    return cA;
  }
  
  public void init()
  {
    byte[] modulusBytes = EncryptionAlgorithm.decode(cv);
    byte[] exponentBytes = EncryptionAlgorithm.decode(cw);
    BigInteger modulus = new BigInteger(1, modulusBytes);
    BigInteger exponent = new BigInteger(1, exponentBytes);
    

    RSAPublicKeySpec rsaPubKey = new RSAPublicKeySpec(modulus, exponent);
    KeyFactory fact = null;
    try
    {
      fact = KeyFactory.getInstance("RSA");
      this.cy = fact.generatePublic(rsaPubKey);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    byte[] expBytes = EncryptionAlgorithm.decode(cx);
    BigInteger privatExponent = new BigInteger(1, expBytes);
    
    RSAPrivateKeySpec privSpec = new RSAPrivateKeySpec(modulus, privatExponent);
    try
    {
      this.cz = fact.generatePrivate(privSpec);
    }
    catch (InvalidKeySpecException e)
    {
      e.printStackTrace();
    }
  }
  
  public byte[] s()
  {
    try
    {
      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(1, this.cy);
      
      return cipher.doFinal(new String("111").getBytes());
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return null;
  }
  
  public byte[] IIIIlIlllllIlllI(byte[] encrypted)
  {
    try
    {
      Cipher cipher = Cipher.getInstance("RSA");
      
      cipher.init(2, this.cz);
      return cipher.doFinal(encrypted);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return null;
  }
  
  public static void main(String[] args)
  {
    byte[] encryptedString = r().s();
    System.out.println(EncryptionAlgorithm.encode(encryptedString));
    String str = "KBpU86TyosO5OzqGLEiZtOAbS0C8hWubQVEBffLZjl9iLLZ1sX0UsKsMYWYirSslI9ePeqh0eVBdLVtZBcZGTBInuR7VaeUw5QKhmpxvM1aJncduvnf3D6kf2g4XI9Xbs98h4eh8PajLLdUKURIIKNDjZSYSPfFAbTkm8JIjmyI=";
    byte[] decodeArr = r().IIIIlIlllllIlllI(EncryptionAlgorithm.decode(str));
    System.out.println(new String(decodeArr));
  }
}
